package com.fm.financemanage.service;

import com.fm.financemanage.mapper.AqConfigMapper;
import com.fm.financemanage.model.po.AqConfig;
import com.fm.financemanage.model.vo.PageVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AqConfigService {

    @Resource
    private AqConfigMapper aqConfigMapper;


    public PageVo<List<AqConfig>> getList(String keyword, Integer page, Integer limit) {
        return new PageVo<List<AqConfig>>(aqConfigMapper.getList(keyword, (page - 1) * limit, limit), aqConfigMapper.count(keyword));
    }

    public void operator(AqConfig aqConfig) {
        if (aqConfig.getId() == null) {
            aqConfig.setCreateTime(LocalDateTime.now());
            aqConfig.setUpdateTime(LocalDateTime.now());
            aqConfig.setState(1);
            aqConfigMapper.insertSelective(aqConfig);
        } else {
            aqConfig.setUpdateTime(LocalDateTime.now());
            aqConfigMapper.updateByPrimaryKeySelective(aqConfig);
        }
    }

    public void removeById(Integer id) {
        aqConfigMapper.deleteByPrimaryKey(id);
    }
}
